let checkAll = Array.from(document.getElementsByClassName('check-all'))
let checkbox = Array.from(document.getElementsByClassName('checkbox'))
let list = []
// check-all绑定点击事件
for (let i = 0; i < checkAll.length; i++) {
  checkAll[i].onchange = function () {
    console.log(this.checked)
    for (let item of checkAll) {
      item.checked = this.checked
    }
    for (let item of checkbox) {
      item.checked = this.checked
    }
  }
}
// checkbox绑定点击事件
for (let i = 0; i < checkbox.length; i++) {
  checkbox[i].onchange = function () {
    let arr = []
    for (let item of checkbox) {
      if (item.checked) {
        arr.push(item.value)
      }
    }
    list = arr
    // 判断所有的checkbox是否都选中，如果有一个没有选中返回false
    let flag = checkbox.every((item) => item.checked === true)
    for (let item of checkAll) {
      item.checked = flag
    }
  }
}
